package com.lishe.lishe.lishe.module.mall.adapter;

import android.app.Activity;
import android.support.v7.widget.GridLayoutManager;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;

import com.lishe.lishe.Imageloader.ImageLoaderUtils;
import com.lishe.lishe.R;
import com.lishe.lishe.lishe.MyRecyclerView.RecyclerviewBaseAdapter;
import com.lishe.lishe.lishe.module.mall.activity.LoadMoreActivity;
import com.lishe.lishe.lishe.module.mall.bean.MallItemObject;

import java.util.List;

/**
 * Created by shino on 2017/11/6.
 * 精选活动
 */

public class MallSelectActivityAdapter extends RecyclerviewBaseAdapter {
    private List<MallItemObject> mallItemObjects;
    private Activity context;

    public MallSelectActivityAdapter(Activity context, List<MallItemObject> mallItemObjects) {
        this.mallItemObjects = mallItemObjects;
        this.context = context;
    }

    @Override
    public RecyclerView.ViewHolder onCreateViewHolderMy(ViewGroup parent, int viewType) {
        RecyclerView.LayoutParams params = new GridLayoutManager.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
        View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_header_image_recyclerview, parent,false);
        view.setLayoutParams(params);
        Holder holder = new Holder(view);
        return holder;
    }

    @Override
    public void onBindViewHolderMy(RecyclerView.ViewHolder holder0, int position) {
        Holder holder = (Holder) holder0;
        final MallItemObject mallItemObject = mallItemObjects.get(position);
        holder.recyclerView.setLayoutManager(new LinearLayoutManager(context, LinearLayout.HORIZONTAL, false));
        ImageLoaderUtils.displayImage(context,mallItemObject.getImg_url(), holder.image);
        holder.adapter.setData(mallItemObject.getMallGoodsItem());
        holder.recyclerView.setAdapter(holder.adapter);
        holder.image.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                //查看更多
                LoadMoreActivity.jump((Activity) context, mallItemObject.getMallGoodsItem().get(mallItemObject.getMallGoodsItem().size() - 1).getItem_id(),
                        mallItemObject.getMallGoodsItem().get(mallItemObject.getMallGoodsItem().size() - 1).getTitle());
            }
        });
//        holder.adapter.setData(mallItemObject.getMallGoodsItem());
    }

    @Override
    public int getItemCountMy() {
        return mallItemObjects == null ? 0 : mallItemObjects.size();
    }

    @Override
    public int getItemViewTypeMy(int position) {
        return 0;
    }

    class Holder extends RecyclerView.ViewHolder {
        ImageView image;
        RecyclerView recyclerView;
        MallSelectActivityItemAdapter adapter;

        public Holder(View itemView) {
            super(itemView);
            image = itemView.findViewById(R.id.image);
            recyclerView = itemView.findViewById(R.id.recyclerView);
            adapter = new MallSelectActivityItemAdapter(context, null);
        }
    }
}
